package 力扣;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a
 * Date: 2022-08-21
 * Time: 14:11
 */
public class check_if_a_word_occurs_as_a_prefix_of_any_word_in_a_sentence {
    public static int isPrefixOfWord(String sentence, String searchWord) {
        String[] str = sentence.split(" ");
        int len = searchWord.length();
        int res = 1;
        for(String x : str){
            if(x.length() >= len && x.substring(0, len).equals(searchWord)){
                return res;
            }
            res++;
        }
        return -1;
    }

    public static void main(String[] args) {
        isPrefixOfWord("i love eating burger", "burg");
    }
}
